package com.broadengate.view.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.broadengate.bean.RuleInfo;
import com.broadengate.bean.UserInfo;
import com.broadengate.service.UserService;

@Controller
@RequestMapping("/UserController")
public class UserController
{
    private final static Logger log = Logger.getLogger(LoginController.class);
    
    @Autowired
    private UserService userService;
    
    /**
     * 获取用户目录树
     * @param userId
     * @param pid
     * @param request
     * @param response
     * @param modelMap
     * @return [参数说明]
     * 
     * @return ModelAndView [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping("/getNavagate")
    public ModelAndView getNavagate(@RequestParam(value = "userId") int userId,
            @RequestParam(value = "pid") String pid, HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap)
    {
        List<RuleInfo> ruleList = userService.getUserRuleList(userId, pid);
        Map<String, List<RuleInfo>> map = new HashMap();
        map.put("navagateList", ruleList);
        modelMap.addAllAttributes(map);
        return new ModelAndView("left/navagate", modelMap);
    }
    
    /**
     * 获取系统所有用户列表
     * @param request
     * @param response
     * @param modelMap
     * @return [参数说明]
     * 
     * @return ModelAndView [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping("/getUserList")
    public ModelAndView getUserList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
    {
        
        List<UserInfo> userList = userService.getUserList();
        Map<String, List<UserInfo>> map = new HashMap();
        map.put("userList", userList);
        modelMap.addAllAttributes(map);
        return new ModelAndView("system/userNameList", modelMap);
    }
    
   
    
}
